package com.it.app;
import com.it.bean.User;
import com.it.service.UserService;
import java.util.Scanner;
public class UserApp {
    public static void main(String[] args) {
        UserService userService = new UserService();
        Scanner sc = new Scanner(System.in);
        while (true) {
            switch (userService.menu()) {
                case 1:
                    String username;
                    for (int i = 0; i < userService.users.length; i++) {
                        System.out.println("添加用户-->"+(i+1));
                        System.out.println("请输入账户名:");
                        username = sc.next();
                        System.out.println("请输入密码:");
                        String password = sc.next();
                        System.out.println("请输入地址:");
                        String addr = sc.next();
                        System.out.println("请输入年龄:");
                        int age = sc.nextInt();
                        //生成对象
                        User user = new User();
                        //给属性赋值
                        user.setUsername(username);
                        user.setPassword(password);
                        user.setAddr(addr);
                        user.setAge(age);
                        userService.addUser(user);
                    }
                    break;
                case 2:
                    System.out.println("删除用户：");
                    System.out.println("请输入要删除的用户名");
                    String username0 = sc.next();
                    userService.delUser(username0);
                    break;
                case 3:
                    System.out.println("修改用户：");
                    System.out.println("请输入要修改的用户名");
                    username = sc.next();
                    userService.updateUser(username);
                    break;
                case 4:
                    System.out.println("查询所有用户：");
                    userService.showAllUser();
                    break;
                case 5:
                    System.out.println("查询单个用户：");
                    System.out.println("请输入要查询的用户名");
                    username = sc.next();
                    userService.findUserById(username);
                    break;
                case 6:
                    System.out.println("随机点名");
                    userService.jpUser();
                    break;
                case 0:
                    userService.exit();
                    break;
                default:
                    System.out.println("输入有误，请重新输入");
                    break;
            }
        }
    }
}
